package edu.ucsd.cse110;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import edu.ucsd.cse110.model.Lift;

public class StatsLiftDetailActivity extends ListActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		int id = getIntent().getExtras().getInt("id");
		super.onCreate(savedInstanceState);
		setTitle("Lift Details");
		Format formatter = new SimpleDateFormat("dd-MMM-yyyy");

		ArrayList<String> liftDetailList = new ArrayList<String>();

		LocalDatabaseManager sqlHelper = new LocalDatabaseManager(this);

		List<Lift> liftList = sqlHelper.getLiftByLiftId(id);
		sqlHelper.close();

		for (int i = 0; i < liftList.size(); i++) {
			// if (liftList.get(i).getWodId() == id) {
			if (liftList.get(i).getRepOne() > 0) {
				liftDetailList.add("One Rep\nDate: "
						+ formatter.format(liftList.get(i).getDateOne()
								.getTime()) + "\nWeight Lifted: "
						+ liftList.get(i).getRepOne() + " lb(s)");
			}
			if (liftList.get(i).getRepThree() > 0) {
				liftDetailList.add("Three Reps\nDate: "
						+ formatter.format(liftList.get(i).getDateThree()
								.getTime()) + "\nWeight Lifted: "
						+ liftList.get(i).getRepThree() + " lb(s)");
			}
			if (liftList.get(i).getRepFive() > 0) {
				liftDetailList.add("Five Reps\nDate: "
						+ formatter.format(liftList.get(i).getDateFive()
								.getTime()) + "\nWeight Lifted: "
						+ liftList.get(i).getRepFive() + " lb(s)");
			}
		}

		setListAdapter(new ArrayAdapter<String>(this, R.layout.liftdetail_item,
				liftDetailList));

		ListView lv = getListView();
		lv.setTextFilterEnabled(true);
	}
}